package com.sheep.jucdemo.part1.part1_7;

/**
 * @Date 2022/4/6 21:38
 * @Created by sheep
 */
public class Test1_7_1 {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                // r如果当前线程被中断则退出循环
                while (!Thread.currentThread().isInterrupted()) {
                    System.out.println(Thread.currentThread() + " hello");
                }
            }
        });
        // 启动子线程
        thread.start();
        // main线程休眠1s
        Thread.sleep(100);
        // 中断子线程
        System.out.println("main thread interrupt thread");
        thread.interrupt();
        // 等待子线程中断完毕,没有join会出现main线程先结束，子线程后结束
        thread.join();
        System.out.println("main is over");
    }
}
